package com.century.sjt.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.century.sjt.R;
import com.century.sjt.entity.AboutSJT;
import com.century.sjt.widget.TitleBar.SjtTitleBar;

/**
 * Created by 炳基 on 2016/6/12.
 */
public class AboutSJTFWActivity extends BaseActivity{
    private SjtTitleBar titleBar;
    private RequestQueue mQueue;
    private LinearLayout layoutSJRZ,layoutKHFW,layoutTSJY;
    private AboutSJT mAboutSJT;
    private LinearLayout layoutTSDH;
    private TextView tvTSPhome;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about_sjt_fw_activity);
        mQueue = Volley.newRequestQueue(this);

        Intent intent = getIntent();
        mAboutSJT=(AboutSJT)intent.getSerializableExtra("aboutSJT");

        initView();
    }
    @Override
    protected  void initView(){

        titleBar = (SjtTitleBar) findViewById(R.id.about_sjt_fw_title);
        //       标题栏
        titleBar.setTitle(getResources().getString(R.string.s_CS));
        titleBar.setLeftIconResource(getResources().getString(R.string.icon_return));
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        layoutSJRZ = (LinearLayout) findViewById(R.id.about_sjt_sjrz);
        layoutKHFW = (LinearLayout) findViewById(R.id.about_sjt_khfw);
        layoutTSJY = (LinearLayout) findViewById(R.id.about_sjt_tsjy);
        layoutTSDH = (LinearLayout) findViewById(R.id.about_sjt_lts_phome);
        tvTSPhome = (TextView) findViewById(R.id.about_sjt_tvts_phome);
        if (mAboutSJT.getTelephone()==null||"".equals(mAboutSJT.getTelephone())){
            tvTSPhome.setEnabled(false);
        }else {
            tvTSPhome.setText(getResources().getString(R.string.text_about_ts_phome)+"："+mAboutSJT.getTelephone().toString());
        }
        layoutTSDH.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //询问是否拨打
                AlertDialog.Builder builder = new AlertDialog.Builder(AboutSJTFWActivity.this);
                builder.setTitle(getResources().getString(R.string.text_prompt));
                builder.setMessage(getResources().getString(R.string.text_about_ts_phome)+mAboutSJT.getTelephone()+", "+getResources().getString(R.string.text_prompt_isphome));
                builder.setPositiveButton(getResources().getString(R.string.btn_yes), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mAboutSJT.getTelephone()));
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    }
                });
                builder.setNegativeButton(getResources().getString(R.string.btn_no), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.setCancelable(false);
                builder.create().show();

            }
        });
    }




    @Override
    protected void onResume() {
        super.onResume();
    }


    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {

    }

}
